import 'dart:io';

import 'package:flutter/material.dart';

import 'package:whale/helper/utils/media_picker.dart';
import 'package:whale/helper/utils/util.dart';
import 'package:whale/pages/im/component/im_input/index.dart';

import 'index.dart';

class ImInputAddController extends GetxController {
  ImInputAddController();
  final controller = Get.find<ImInputController>();
  final state = ImInputAddState();

  /// 在 widget 内存中分配后立即调用。
  @override
  void onInit() {
    super.onInit();
    state.list = [
      ImInputAddModel(
          data: Icons.photo_camera,
          text: '拍摄',
          onTap: () {
            pickerPhoto();
          }),
      ImInputAddModel(data: Icons.video_chat, text: '视频通话', onTap: () {}),
      ImInputAddModel(
          data: Icons.location_on,
          text: '位置',
          onTap: () {
            controller.actionSendLocation(
                path:
                    'https://mbd.baidu.com/newspage/data/landingsuper?context=%7B%22nid%22%3A%22news_10063549210058111273%22%7D&n_type=-1&p_from=-1');
          }),
      ImInputAddModel(
          data: Icons.people,
          text: '名片',
          onTap: () {
            controller.actionSendCard(
                path:
                    'https://mbd.baidu.com/newspage/data/landingsuper?context=%7B%22nid%22%3A%22news_10063549210058111273%22%7D&n_type=-1&p_from=-1');
          }),
    ];
  }

  Future<void> pickerPhoto() async {
    var files = await MediaPicker.pickImages();
    if (files.isEmpty) return;
    for (var e in files) {
      Image img = Image.file(File(e.path!));
      controller.actionSendPicture(
          path: e.path!, width: img.width, height: img.height);
    }
  }

  /// 在 onInit() 之后调用 1 帧。这是进入的理想场所
  @override
  void onReady() {
    super.onReady();
  }

  /// 在 [onDelete] 方法之前调用。
  @override
  void onClose() {
    super.onClose();
  }

  /// dispose 释放内存
  @override
  void dispose() {
    super.dispose();
  }
}
